package data;

import java.util.Arrays;
import java.util.List;

import com.google.common.collect.Lists;

public class CardsManager
{
    private boolean _cards_exported = false;
    private VotingCard _basic_card = new VotingCard( true );
    private int _NUMBER_OF_SETS = 100;

    public CardsManager()
    {
    }

    public CardsManager( String candidates )
    {
        String[] splitted = candidates.split( "\r\n" );
        splitted = Arrays.copyOf( splitted, splitted.length - 1 );
        for( String candidate: splitted )
        {
            // System.out.println( "CardsManager: " + candidate );
            addCandidate( candidate );
        }
    }

    public void addCandidate( String name )
    {
        if( _cards_exported )
            throw new RuntimeException( "Cannot add new candidates, when cards have been already exported" );
        _basic_card.addCandidate( name );
    }

    public int getNumberOfCandidates()
    {
        return _basic_card.getCandidates().size();
    }

    public List<VotingSet> exportSets()
    {
        _cards_exported = true;
        List<VotingSet> list = Lists.newLinkedList();
        for( int i = 0; i < _NUMBER_OF_SETS; i++ )
        {
            VotingSet set = new VotingSet( _basic_card );
            list.add( set );
            _basic_card.setNewRandomId();
        }
        return list;
    }
}
